package com.song.JavaThread_day07.ch7_4;

import java.util.Date;

public class MyThread  extends Thread{
	
	
	private Date creationDate;
	
	private Date startDate;
	
	private Date finishDate;

	public MyThread(Runnable target, String name) {
		super(target, name);
		setCreationDate();
	}

	private void setCreationDate() {
		creationDate = new Date();
		
	}

	@Override
	public void run() {
		setStartDate();
		super.run();
		setFinishDate();
	}

	private void setFinishDate() {
		// TODO Auto-generated method stub
		finishDate = new Date();
	}

	private void setStartDate() {
		// TODO Auto-generated method stub
		startDate = new Date();
	}
	
	public long getExecutionTime()
	{
		return finishDate.getTime() - startDate.getTime();
	}

	@Override
	public String toString() {
		
		StringBuilder sb = new StringBuilder();
		sb.append(getName());
		sb.append(" : ");
		sb.append(" creation Date: ");
		sb.append(creationDate);
		sb.append(" :  Running time :");
		sb.append(getExecutionTime());
		sb.append("  Milliseconds ");
		return sb.toString();
		
	}
	
	
}
